package com.hontech.pastacooking.activity.fragment.sub

import android.view.View
import android.widget.Button
import android.widget.EditText
import com.hontech.pastacooking.R
import com.hontech.pastacooking.activity.window.showProg
import com.hontech.pastacooking.app.onClick
import com.hontech.pastacooking.app.toInt
import com.hontech.pastacooking.conn.HeaterProto
import com.hontech.pastacooking.conn.requestHeater
import com.hontech.pastacooking.serial.UInt16
import com.hontech.pastacooking.utils.S.t274
import com.hontech.pastacooking.utils.S.t275
import com.hontech.pastacooking.utils.S.t276

class MiniWeightDelegate (view: View) {

    private val etWeight = view.findViewById<EditText>(R.id.id_input_mini_weight)
    private val btnSet = view.findViewById<Button>(R.id.id_btn_mini_weight_set)

    init {
        btnSet.onClick(::onClickSet)
    }

    private suspend fun onClickSet() {
        val w = showProg(btnSet, t274)

        try {
            val value = etWeight.toInt()
            requestHeater(5 * 1000L,
                HeaterProto.SetMiniBucketWeight,
                arrayOf(UInt16(value)),
                t275
            )
            w.success(t276)
        } catch (e: Exception) {
            e.printStackTrace()
            w.error(e.message!!)
        }
    }
}